package com.web.controller;

import com.web.entity.Person;
import com.web.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/person")
public class PersonController {
    @Autowired
    private PersonService personService;

    @RequestMapping("/index_show")//不能和返回值相同，不然会报错
    //@ResponseBody//表示直接返回json
    public String show1() {
        return "index";
    }
    @RequestMapping("/add")//往person表中添加数据
    public String insertPerson(HttpServletRequest request)
    {
        Person person = new Person();
        person.setId(Integer.parseInt(request.getParameter("id")));
        person.setName(request.getParameter("name"));
        personService.insertPerson(person);
        return "redirect:index.html";//重定向
//        解决Request method 'POST' not supported问题的4种方法
//        1、将login.html中表单提交方式改为GET
//        2、将 return “/login.html”; 改为 return “redirect:/login.html”;
//        3、将前端HTML改用JSP
//        4、security的配置文件中使用.defaultSuccessUrl("/index")
    }
}
